import game from "./game";
import enemyCtrl from "./enemyCtrl";
import enemyCtrl_2 from "./enemyCtrl_2";
import enemyCtrl_3 from "./enemyCtrl_3";



const { ccclass, property } = cc._decorator;

@ccclass
export default class bulletCtrl_3 extends cc.Component {



    // LIFE-CYCLE CALLBACKS:
    @property
    speed: number = 500;

    //scr=cc.find('Canvas').getComponent(game);

    onLoad() {

    }

    start() {

        // let gg = cc.find("Canvas");
        // let sc = gg.getComponent(game);
        // if (cc.find('Canvas').getComponent(game).gameType == 1 || sc.gameType == 3) {
        //     let m1 = cc.moveTo(1 , cc.v2(220,447));
        //     this.node.runAction(m1)
        //     //cc.log("gggg"+cc.find('Canvas').getComponent(game).gameType);
        //     // this.node.y += this.speed * dt;
        // }
        // let scr=cc.find('Canvas').getComponent(game);
        // let c =scr.gameType;
        // cc.log("gggg"+c);
        //this.getComponent(game).gameType
        //game.instance.gameType

    }

    onCollisionEnter(other, self) {
        //console.log("zhuangle");
        //let gTs=new game();
        //gTs.onBulletKilled(this.node);
        let gg = cc.find("Canvas");
        let sc = gg.getComponent(game);
        if (self.tag == 11) {
            sc.onBullet3Killed(self.node);
            //sc.onBullet2Killed(self.node);
        }
        //sc.onEnemyKilled(other.node);
        if (other.tag == 111) {
            // let js = other.node.getComponent('enemyCtrl')
            // if(js && js.isDie == false){
            //     js.hit()
            // }
            //let js = other.node.getComponent('enemyCtrl')
            let js = other.node.getComponent(enemyCtrl)
            if (js && js.isDie == false) {
                js.hit();
            }
        } else if (other.tag == 2) {
            let js = other.node.getComponent(enemyCtrl_2);
            if (js && js.isDie == false) {
                js.hit();
            }
        } else if (other.tag == 3) {
            let js = other.node.getComponent(enemyCtrl_3);
            if (js && js.isDie == false) {
                js.hit();
            }
        }
    }

    update(dt) {
        let gg = cc.find("Canvas");
        let sc = gg.getComponent(game);
        if (cc.find('Canvas').getComponent(game).gameType == 1 || sc.gameType == 3) {
            
                // let m1 = cc.moveTo(1 , cc.v2(220,447));
                // this.node.runAction(m1)
          
            // let m1 = cc.moveTo(1 , cc.v2(220,447));
            // this.node.runAction(m1)
            //cc.log("gggg"+cc.find('Canvas').getComponent(game).gameType);
            this.node.y += 500 * dt;
            this.node.x +=150*dt;
        }
        if (this.node.y >= 510) {
            sc.onBullet3Killed(this.node);
            //sc.onBullet2Killed(this.node);
            //console.log("destory");

        }










        //this.node.y+=this.speed*dt;

        //  if(this.node.y > cc.winSize.height){
        //     this.node.destroy();
        //     console.log("destory");

        // }
    }
}
